package com.wehealth.three.lib_connect.utils;

import android.util.Log;


import java.util.HashSet;
import java.util.Set;

public class ECGDataAutoAnalyseUtils {

    /***
     * 获取分析到的心电结果
     * @param index
     * @return
     */
    public static Set<String> getAnalyseResult(int[] index) {
        Set<String> set = new HashSet<>();
        for (int i = 0; i < index.length; i++) {
            set.add(analyseResult[index[i]]);
        }
        return set;
    }

    /***
     * 自动分析心电书数据
     * @param type
     * @param index
     * @return
     */
    public static String analyseECGDataResult(int type, int[] index) {
        boolean isAnalyseFailed = true;//是否全是0，全是0：true，否则为false
        for (int i = 0; i < index.length; i++) {
            Log.e("TAG", "结论：" + index[i] + "");
            if (index[i] != 0) {//有不等于0的结论
                isAnalyseFailed = false;
                break;
            }
        }
        String typECG = "";
        if (type == 500) {
            typECG = analyseType[0];
        }
        if (type == 501) {
            typECG = analyseType[1];
        }
        if (type == 502) {
            typECG = analyseType[2];
        }
        if (type == 503) {
            typECG = analyseType[3];
        }
        ECGDataUtil.ECGDataResultHelper helper = new ECGDataUtil.ECGDataResultHelper();
        if (!isAnalyseFailed) {
            for (int i = 0; i < index.length; i++) {
                if (index[i] != 0) {
                    helper.getResult().put(String.valueOf(index[i]), analyseResult[index[i]]);
                }
            }
            helper.getClassfy().put(String.valueOf(type), typECG);
        } else {//分析失败
            helper.getResult().put(String.valueOf(0), "正常心电图");
            if (type == 0) {
                helper.getClassfy().put(0 + "", "分析失败");
            } else {
                helper.getClassfy().put(type + "", typECG);
            }

        }
        return ECGDataUtil.encodeEcgResult(helper);
    }

    public static String[] analyseType = new String[]{
            "** 正常心电图 **",
            "** 非典型心电图 **",
            "** 可疑心电图 **",
            "** 异常心电图 **"
    };

    private static String[] analyseResult = new String[]{
            "正常心电图",
            "窦性心律",
            "心动过速",
            "窦性心动过速",
            "室上性心动过速",
            "阵发性室上性心动过速",
            "室性心动过速",
            "短阵室性心动过速",
            "心动过缓",
            "窦性心动过缓",
            "窦性心动过缓伴不齐",
            "窦性心律不齐",
            "室性早搏",
            "成对室性早搏",
            "多形性室性早搏",
            "多源性室性早搏",
            "频发室性早搏",
            "室性早搏二联律",
            "室性早搏三联律",
            "室上性早搏",
            "偶发室上性早搏",
            "成对室上性早搏",
            "频发室上性早搏",
            "室上性早搏二联律",
            "室上性早搏三联律",
            "心房颤动 ",
            "心房扑动",
            "心室颤动",
            "心室扑动",
            "阵发性心房颤动",
            "全心停搏",
            "I度房室传导阻滞",
            "II度I型房室传导阻滞",
            "II度II型房室传导阻滞",
            "III度房室传导阻滞",
            "不完全右束支传导阻滞",
            "完全右束支传导阻滞",
            "不完全左束支传导阻滞",
            "完全左束支传导阻滞",
            "室内传导阻滞",
            "左前分支阻滞",
            "左后分支阻滞",
            "预激综合症",
            "左心房肥大",
            "怀疑左心房肥大",
            "右心房肥大",
            "怀疑右心房肥大",
            "双心房肥大",
            "怀疑双心房肥大",
            "左心室肥大",
            "怀疑左心室肥大",
            "左心室肥大伴ST-T改变",
            "左室高电压",
            "右心室肥大",
            "怀疑右心室肥大",
            "右室肥大伴ST-T改变",
            "急性前壁心肌梗死",
            "亚急性前壁心肌梗死",
            "陈旧性前壁心肌梗死",
            "急性前间壁心肌梗死",
            "亚急性前间壁心肌梗死",
            "陈旧性前间壁心肌梗死",
            "急性广泛前壁心肌梗死",
            "亚急性广泛前壁心肌梗死",
            "陈旧性广泛前壁心肌梗死",
            "急性侧壁心肌梗死",
            "亚急性侧壁心肌梗死",
            "陈旧性侧壁心肌梗死",
            "急性高侧壁心肌梗死",
            "亚急性高侧壁心肌梗死",
            "陈旧性高侧壁心肌梗死",
            "急性下壁心肌梗死",
            "亚急性下壁心肌梗死",
            "陈旧性下壁心肌梗死",
            "不确定心电轴",
            "轻度电轴左偏",
            "电轴左偏",
            "轻度电轴右偏",
            "电轴右偏",
            "ST-T改变",
            "ST段抬高",
            "ST段下降",
            "T波高耸",
            "T波低平",
            "T波倒置",
            "PR间期缩短",
            "QT间期缩短",
            "QT间期延长",
            "异常Q波",
            "肢体导联低电压",
            "胸导联低电压",
            "全导联低电压",
            "右位心",
            "心房起搏心电图",
            "心室起搏心电图",
            "双腔起搏心电图",
            "早期复极综合征",
            "窦性停搏",
            "顺钟向转位",
            "逆钟向转位",
            "S1S2S3 综合征",
            "过速性心房颤动"
    };

}
